import { api } from "../api"

export function fetchChapterApi(courseFileId: any, sentence: string) {
  try {
    return api.get('/java/teacher/StudySpaceTeacher/sorted-resources', {
      params: {
        courseFileId,
        sentence,
      },
    });
  }
  catch (error) {
    throw new Error('获取章节资源失败')
  }
}

export function handleChapterDropApi(payload: any) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/updateSortOrder', payload);
  }
  catch (error) {
    throw new Error('排序失败')
  }
}

export function creatChapterApi(courseFile_id: string | null, file_name: string, sort_order: number) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/newcreateChapter', null, {
      params: {
        courseFile_id,
        file_name,
        sort_order,
      },
    });
  }
  catch (error) {
    throw new Error('创建失败')
  }
}

export function deleteChapterApi(courseId: string | null, courseFileId: string) {
  try {
    return api.get('/java/teacher/StudySpaceTeacher/deleteFiles', {
      params: {
        courseId,
        courseFileId,
      },
    })
  }
  catch (error) {
    throw new Error('删除课程失败');
  }
}

export function RenameChapterApi(courseFileId: string, newFileName: string) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/updateCourseFileName', null, {
      params: {
        courseFileId,
        newFileName,
        type: '文件夹',
      },
    });
  }
  catch (error) {
    throw new Error('课程重命名失败');
  }
}
